<template>
  <div class="drag-and-drop-container">
    <json-editor-vue v-model="data" class="mb-4" @node-click="onNodeClick"></json-editor-vue>
    <div>输入JSON</div>
    <textarea v-model="txt" class="w-full h-72 p-2 border border-gray-300 rounded-md mb-4"></textarea>
    <button @click="onSure" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-md">确定</button>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, defineProps } from 'vue';
import JsonEditorVue from 'json-editor-vue';

const emits = defineEmits(["setName"])
const data = ref<any>({});
const txt = ref(localStorage.getItem("txt") || "");

const onSure = () => {
  localStorage.setItem("txt", txt.value);
  data.value = JSON.parse(txt.value);
  emits("setName", data.value.dsName)
};

// 新增的函数，用于处理节点点击事件
const onNodeClick = (node: any) => {
  console.log('Clicked node value:', node);
};
</script>

<style scoped></style>
